Skip to content

OCPEDGE-2118: Record Kubernetes events for etcd transition lifecycle#1653

Open
lucaconsalvi wants to merge 5 commits into
openshift:mainfrom
lucaconsalvi:ocpedge-2118-etcd-transition-events
Open

OCPEDGE-2118: Record Kubernetes events for etcd transition lifecycle#1653
lucaconsalvi wants to merge 5 commits into
openshift:mainfrom
lucaconsalvi:ocpedge-2118-etcd-transition-events

Conversation

@lucaconsalvi

@lucaconsalvi lucaconsalvi commented Jul 16, 2026

Copy link
Copy Markdown

Add event recording to the TNF setup runner and etcd transition code so the full CEO-to-pacemaker handoff is observable via kubectl get events -n openshift-etcd.

Nine events are emitted across the transition lifecycle:

  • runner.go: auth, cluster, fencing, etcd resource, constraints
  • etcd.go: transition started, waiting, static pod removed, completed

Events use the direct K8s API (not library-go Recorder) since the setup runner is a short-lived Job. Failures are logged but never block the transition.

Summary by CodeRabbit

  • New Features
    • Added Kubernetes event reporting for key TNF setup milestones and etcd transition progress.
    • Recorded events cover transition start, waiting for static etcd removal, and transition completion.
    • Added tooling to validate and inspect transition-related events.
  • Bug Fixes
    • Setup continues reliably even if event recording fails.

Add event recording to the TNF setup runner and etcd transition
code so the full CEO-to-pacemaker handoff is observable via
`kubectl get events -n openshift-etcd`.

Nine events are emitted across the transition lifecycle:
- runner.go: auth, cluster, fencing, etcd resource, constraints
- etcd.go: transition started, waiting, static pod removed, completed

Events use the direct K8s API (not library-go Recorder) since the
setup runner is a short-lived Job. Failures are logged but never
block the transition.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci

openshift-ci Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci-robot

openshift-ci-robot commented Jul 16, 2026

Copy link
Copy Markdown

@lucaconsalvi: This pull request references OCPEDGE-2118 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Add event recording to the TNF setup runner and etcd transition code so the full CEO-to-pacemaker handoff is observable via kubectl get events -n openshift-etcd.

Nine events are emitted across the transition lifecycle:

  • runner.go: auth, cluster, fencing, etcd resource, constraints
  • etcd.go: transition started, waiting, static pod removed, completed

Events use the direct K8s API (not library-go Recorder) since the setup runner is a short-lived Job. Failures are logged but never block the transition.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jul 16, 2026
@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 8f378aa3-4dd8-44be-8c58-bab308cd99c1

📥 Commits

Reviewing files that changed from the base of the PR and between 76d363d and d31a9b2.

📒 Files selected for processing (1)
  • pkg/tnf/hack/test-transition-events.sh
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/tnf/hack/test-transition-events.sh

Walkthrough

TNF setup now records Kubernetes events for configuration milestones and the etcd transition lifecycle. RemoveStaticContainer accepts a Kubernetes client, emits transition events, and tests and a helper script validate event creation and metadata.

Changes

TNF transition events

Layer / File(s) Summary
Kubernetes event recording
pkg/tnf/pkg/tools/events.go
Adds RecordSetupEvent to create Normal events for the TNF setup job in the openshift-etcd namespace.
Setup milestone emission
pkg/tnf/setup/runner.go
Records events after authentication, PCS, fencing, resource-agent, and constraint configuration, and passes kubeClient to the etcd handover.
Static etcd transition and validation
pkg/tnf/pkg/etcd/etcd.go, pkg/tnf/pkg/etcd/etcd_test.go, pkg/tnf/hack/test-transition-events.sh
Records etcd transition milestones, updates the function signature and wait helper, validates operator conditions and event metadata, and adds event-generation verification.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RunTnfSetup
  participant RecordSetupEvent
  participant RemoveStaticContainer
  participant KubernetesEvents
  RunTnfSetup->>RecordSetupEvent: record setup milestone
  RunTnfSetup->>RemoveStaticContainer: hand over with kubeClient
  RemoveStaticContainer->>RecordSetupEvent: record transition milestone
  RecordSetupEvent->>KubernetesEvents: create Normal Event
Loading

Suggested reviewers: jaypoulz, kaleemsiddiqu

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: recording Kubernetes events for the etcd transition lifecycle.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed No Ginkgo titles were added; the only test name is static (TestRemoveStaticContainer) and contains no dynamic values.
Test Structure And Quality ✅ Passed PASS: This is a plain unit test, not Ginkgo; it uses fake clients, has no waits or cluster resources, and follows repo patterns, so the listed Ginkgo-specific concerns don’t apply.
Microshift Test Compatibility ✅ Passed No new Ginkgo e2e tests were added; the PR only changes a unit test and a shell helper, so the MicroShift check is not applicable.
Single Node Openshift (Sno) Test Compatibility ✅ Passed No new Ginkgo e2e tests were added; the new test is a standard Go unit test and the shell script is not topology-dependent.
Topology-Aware Scheduling Compatibility ✅ Passed PR only adds event recording and transition flow changes; no manifests, replicas, affinity, nodeSelectors, or topology-dependent scheduling logic were introduced.
Ote Binary Stdout Contract ✅ Passed No new process-level stdout writes were added; the PR only adds K8s event writes and klog logging, and klog defaults to stderr.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No new Ginkgo e2e tests were added; the new unit test and helper script use fake/in-cluster Kubernetes APIs and show no IPv4 or public-internet assumptions.
No-Weak-Crypto ✅ Passed No MD5/SHA1/DES/RC4/3DES/Blowfish/ECB, custom crypto, or secret/token comparisons found in the touched event-recording changes.
Container-Privileges ✅ Passed PR only adds a shell script creating Event objects; no new privileged containers/manifests or hostPID/hostNetwork/allowPrivilegeEscalation settings were introduced.
No-Sensitive-Data-In-Logs ✅ Passed Added logs only emit fixed transition reasons/messages; no passwords, tokens, PII, or hostnames are logged in the new code paths.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/tnf/pkg/tools/events.go`:
- Around line 3-28: Update RecordSetupEvent so the reason component used in the
event metadata.name is converted to lowercase before constructing the name.
Preserve the existing event naming format and reason value used elsewhere in the
event.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 11fb1836-7157-46ed-9989-87c3820a66e7

📥 Commits

Reviewing files that changed from the base of the PR and between 1fe5873 and 4bd68bb.

📒 Files selected for processing (5)
  • hack/test-transition-events.sh
  • pkg/tnf/pkg/etcd/etcd.go
  • pkg/tnf/pkg/etcd/etcd_test.go
  • pkg/tnf/pkg/tools/events.go
  • pkg/tnf/setup/runner.go

Comment thread pkg/tnf/pkg/tools/events.go
@lucaconsalvi
lucaconsalvi marked this pull request as ready for review July 16, 2026 12:23
@openshift-ci openshift-ci Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 16, 2026
The event reason (e.g. EtcdTransitionAuthCompleted) was used directly
in metadata.name which should be a valid lowercase DNS subdomain.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@openshift-ci
openshift-ci Bot requested review from jaypoulz and kaleemsiddiqu July 16, 2026 12:28
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@fonta-rh fonta-rh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, I'm amazed, I have nothing to nitpick. This does what it should minimally, good test coverage! Good work!

@fonta-rh

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Jul 17, 2026
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling required tests:
/test e2e-agnostic-ovn
/test e2e-agnostic-ovn-upgrade
/test e2e-aws-ovn-serial-1of2
/test e2e-aws-ovn-serial-2of2
/test e2e-aws-ovn-single-node
/test e2e-gcp-operator
/test e2e-gcp-operator-disruptive
/test e2e-metal-ipi-ovn-ipv6
/test e2e-operator

@lucaconsalvi

Copy link
Copy Markdown
Author

E2E Verification on Live TNF Cluster

Cluster: Deployed via cluster-bot (workflow-launch baremetalds-two-node-fencing) with the CEO image built from this PR.

Method: Verified all 9 transition events are emitted during the CEO-to-Pacemaker etcd handoff using oc get events -n openshift-etcd.

Results

All 9 events recorded successfully in openshift-etcd namespace:

# Reason Source Status
1 EtcdTransitionAuthCompleted tnf-setup-runner PASS
2 EtcdTransitionClusterConfigured tnf-setup-runner PASS
3 EtcdTransitionFencingConfigured tnf-setup-runner PASS
4 EtcdTransitionEtcdResourceCreated tnf-setup-runner PASS
5 EtcdTransitionConstraintsConfigured tnf-setup-runner PASS
6 EtcdTransitionStarted tnf-setup-runner PASS
7 EtcdTransitionWaitingForRemoval tnf-setup-runner PASS
8 EtcdTransitionStaticContainerRemoved tnf-setup-runner PASS
9 EtcdTransitionCompleted tnf-setup-runner PASS
  • All events are Normal type with InvolvedObject: Job/tnf-setup-job
  • Event names comply with RFC 1123 subdomain rules (lowercase)
  • Events are visible in both the OpenShift console (Events tab) and CLI
  • Event recording failures are logged but do not block the setup — non-blocking by design

/verified by @lucaconsalvi

@openshift-ci-robot openshift-ci-robot added the verified Signifies that the PR passed pre-merge verification criteria label Jul 17, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@lucaconsalvi: This PR has been marked as verified by @lucaconsalvi.

Details

In response to this:

E2E Verification on Live TNF Cluster

Cluster: Deployed via cluster-bot (workflow-launch baremetalds-two-node-fencing) with the CEO image built from this PR.

Method: Verified all 9 transition events are emitted during the CEO-to-Pacemaker etcd handoff using oc get events -n openshift-etcd.

Results

All 9 events recorded successfully in openshift-etcd namespace:

# Reason Source Status
1 EtcdTransitionAuthCompleted tnf-setup-runner PASS
2 EtcdTransitionClusterConfigured tnf-setup-runner PASS
3 EtcdTransitionFencingConfigured tnf-setup-runner PASS
4 EtcdTransitionEtcdResourceCreated tnf-setup-runner PASS
5 EtcdTransitionConstraintsConfigured tnf-setup-runner PASS
6 EtcdTransitionStarted tnf-setup-runner PASS
7 EtcdTransitionWaitingForRemoval tnf-setup-runner PASS
8 EtcdTransitionStaticContainerRemoved tnf-setup-runner PASS
9 EtcdTransitionCompleted tnf-setup-runner PASS
  • All events are Normal type with InvolvedObject: Job/tnf-setup-job
  • Event names comply with RFC 1123 subdomain rules (lowercase)
  • Events are visible in both the OpenShift console (Events tab) and CLI
  • Event recording failures are logged but do not block the setup — non-blocking by design

/verified by @lucaconsalvi

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@lucaconsalvi

Copy link
Copy Markdown
Author

/retest

1 similar comment
@lucaconsalvi

Copy link
Copy Markdown
Author

/retest

@fonta-rh

Copy link
Copy Markdown
Contributor

/approve

@lucaconsalvi

Copy link
Copy Markdown
Author

/retest

1 similar comment
@lucaconsalvi

Copy link
Copy Markdown
Author

/retest

TNF-specific manual validation script belongs under the TNF directory
tree rather than the repo-wide hack/ directory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@openshift-ci-robot openshift-ci-robot removed the verified Signifies that the PR passed pre-merge verification criteria label Jul 21, 2026
@openshift-ci openshift-ci Bot removed the lgtm Indicates that a PR is ready to be merged. label Jul 21, 2026
@openshift-ci

openshift-ci Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

@openshift-ci-robot

openshift-ci-robot commented Jul 21, 2026

Copy link
Copy Markdown

@lucaconsalvi: This pull request references OCPEDGE-2118 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Add event recording to the TNF setup runner and etcd transition code so the full CEO-to-pacemaker handoff is observable via kubectl get events -n openshift-etcd.

Nine events are emitted across the transition lifecycle:

  • runner.go: auth, cluster, fencing, etcd resource, constraints
  • etcd.go: transition started, waiting, static pod removed, completed

Events use the direct K8s API (not library-go Recorder) since the setup runner is a short-lived Job. Failures are logged but never block the transition.

Summary by CodeRabbit

  • New Features

  • Added Kubernetes events to track key setup milestones and etcd transition progress.

  • Events identify when setup starts, reaches major configuration milestones, waits for static etcd removal, and completes.

  • Added validation tooling for inspecting transition events.

  • Bug Fixes

  • Setup continues reliably even if event recording fails.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci

openshift-ci Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fonta-rh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 21, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/tnf/hack/test-transition-events.sh (1)

60-60: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Return a non-zero exit code on verification failure.

If grep fails to find any EtcdTransition events, the script currently prints an error message but still exits with a 0 (success) code due to the || echo ... fallback. For a validation script, it is a best practice to exit with a non-zero code to accurately reflect the failure.

Additionally, the empty quotes in --field-selector reason!=="" are consumed by Bash and passed to oc as reason!=. It is better to quote the entire argument or omit the empty quotes for clarity.

♻️ Proposed refactor
-oc get events -n "${NAMESPACE}" --field-selector reason!=="" --sort-by='.lastTimestamp' | grep -i "EtcdTransition" || echo "No EtcdTransition events found!"
+oc get events -n "${NAMESPACE}" --field-selector reason!= --sort-by='.lastTimestamp' | grep -i "EtcdTransition" || { echo "No EtcdTransition events found!"; exit 1; }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/tnf/hack/test-transition-events.sh` at line 60, Update the EtcdTransition
verification command to pass the field selector as a single correctly quoted
argument, avoiding Bash stripping the empty quotes. Replace the grep fallback in
the validation flow so missing EtcdTransition events exits with a non-zero
status after reporting the failure, while preserving successful behavior when
matching events are found.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/tnf/hack/test-transition-events.sh`:
- Line 63: Label the mock Event manifest metadata with tnf-test="true", then
update the cleanup instruction to use -l 'tnf-test=true' so only mock events are
targeted; apply both changes in pkg/tnf/hack/test-transition-events.sh at lines
33-52 and 63.

---

Nitpick comments:
In `@pkg/tnf/hack/test-transition-events.sh`:
- Line 60: Update the EtcdTransition verification command to pass the field
selector as a single correctly quoted argument, avoiding Bash stripping the
empty quotes. Replace the grep fallback in the validation flow so missing
EtcdTransition events exits with a non-zero status after reporting the failure,
while preserving successful behavior when matching events are found.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 4adac7d9-d4a5-49d9-849c-cd337ac96d6b

📥 Commits

Reviewing files that changed from the base of the PR and between d75bdc7 and 76d363d.

📒 Files selected for processing (1)
  • pkg/tnf/hack/test-transition-events.sh

Comment thread pkg/tnf/hack/test-transition-events.sh Outdated
Add tnf-test=true label to mock events so the cleanup command only
targets test events, not real cluster diagnostic data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lucaconsalvi

Copy link
Copy Markdown
Author

/retest

@lucaconsalvi

Copy link
Copy Markdown
Author

/test e2e-aws-ovn-single-node

@lucaconsalvi

Copy link
Copy Markdown
Author

/verified by @lucaconsalvi

@openshift-ci-robot openshift-ci-robot added the verified Signifies that the PR passed pre-merge verification criteria label Jul 22, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@lucaconsalvi: This PR has been marked as verified by @lucaconsalvi.

Details

In response to this:

/verified by @lucaconsalvi

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci

openshift-ci Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

@lucaconsalvi: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-aws-ovn-single-node d31a9b2 link true /test e2e-aws-ovn-single-node

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@lucaconsalvi

Copy link
Copy Markdown
Author

/retest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. verified Signifies that the PR passed pre-merge verification criteria

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants